package com.sc.HadoopStaffCompute;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import com.sc.bean.Spend;
import com.sc.bean.SpendSecond;
import com.sc.mapper.StaffComouteMapper;
import com.sc.mapper.StaffPartMapper;
import com.sc.part.CityPart;
import com.sc.reducer.StaffComputeReducer;
import com.sc.reducer.StaffComputeSortReducer;
import com.sc.reducer.StaffPartReducer;

/**
 * Hello world!
 *
 */
public class App 
{
    @SuppressWarnings("deprecation")
	public static void main( String[] args ) throws IOException, ClassNotFoundException, InterruptedException
    {
    	//程序启动
        Configuration configuration = new Configuration();
        Job job = new Job(configuration);
        
        //设置包含main的类
        job.setJarByClass(App.class);
        
        //设置mapper类
//        job.setMapperClass(StaffComouteMapper.class);
        job.setMapperClass(StaffPartMapper.class);
        
        //设置reducer类
//        job.setReducerClass(StaffComputeReducer.class);
        job.setReducerClass(StaffPartReducer.class);
        
        //设置数据分区
        //指定数据分区规则，不是必须要的，根据业务需求分区
        job.setPartitionerClass(CityPart.class);
        //设置相应的reducer数量，要与分区的最大数量一致
        job.setNumReduceTasks(8);
        
        //设置输出键和值类型
        job.setMapOutputKeyClass(Text.class);
//        job.setMapOutputValueClass(FloatWritable.class);
        job.setMapOutputValueClass(SpendSecond.class);
        
        job.setOutputKeyClass(Text.class);
//        job.setOutputKeyClass(FloatWritable.class);
//        job.setOutputValueClass(Spend.class);
        job.setOutputValueClass(SpendSecond.class);
        
        //设置hadoop的文件路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        //结果输出路径
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        
        //等待打印日志
        job.waitForCompletion(true);
    }
}
